package project.vip.services.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import kernel.web.Page;
import kernel.web.PagedQueryDao;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import project.product.Brand;
import project.product.Cloth;
import project.product.Stlye;
import project.vip.po.Ad;
import project.vip.services.AdminAdService;

public class AdminAdServiceImpl extends HibernateDaoSupport implements AdminAdService {

    private PagedQueryDao pagedQueryDao;
    
    @Override
    public List<Ad> getAll() {
        StringBuffer queryString = new StringBuffer(" FROM Ad WHERE shelves = ? ORDER BY order");
        return this.getHibernateTemplate().find(queryString.toString(),new Object[]{true});
    }
    
    @Override
    public Page pagedQuery(int pageNo, int pageSize, String phone) {
        StringBuffer queryString = new StringBuffer(" FROM Ad WHERE 1=1 ");

        Map<String, Object> parameters = new HashMap<String, Object>();
     
        queryString.append(" order by createTime desc ");
        Page page = pagedQueryDao.pagedQuery(pageNo, pageSize, queryString.toString(), parameters);
        return page;

    }

    public void setPagedQueryDao(PagedQueryDao pagedQueryDao) {
        this.pagedQueryDao = pagedQueryDao;
    }

    @Override
    public Ad getById(Serializable id) {
        StringBuffer queryString = new StringBuffer(" FROM Ad where id=?");
        List<Ad> list = this.getHibernateTemplate().find(queryString.toString(), id);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public void save(Ad entity) {
        entity.setCreateTime(new Date());
        this.getHibernateTemplate().save(entity);

    }

    @Override
    public void update(Ad entity) {
        this.getHibernateTemplate().update(entity);

    }
    @Override
    public void delete(Serializable id) {

        Ad en = this.getHibernateTemplate().get(Ad.class, id);
        if (en != null) {
        	this.getHibernateTemplate().delete(en);
        }
    }

	
}
